package com.crm.controller;


import com.crm.common.annotation.Log;
import com.crm.common.enums.BusinessType;
import com.crm.common.page.TableDataInfo;
import com.crm.common.result.AjaxResult;
import com.crm.common.result.PageResult;
import com.crm.common.result.Result;
import com.crm.common.utils.UserThreadLocal;
import com.crm.domain.Activity;
import com.crm.dto.ActivityPageQueryDTO;
import com.crm.service.ActivityService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clues/activity")
@RequiredArgsConstructor
@Slf4j
public class ActivityController {

    private final ActivityService activityService;

    /*
    * 新增活动
    * */
    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("新增活动：{}",activity);
        activityService.add(activity);
        return Result.success();
    }
    /*
    * 根据id查询
    * */

    @GetMapping("/{id}")
    public Result<Activity> selectById(@PathVariable Integer id){
        Activity activity = activityService.selectById(id);
        return Result.success(activity);
    }
    /*
    * 根据id删除活动
    * */

    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Long id){
        //获取当前用户id
        Long userId = UserThreadLocal.getUserId();
        log.info("打印当前用户id：{}",userId);
        activityService.deleteById(id);
        return AjaxResult.success();
    }
    /*
    * 修改活动
    * */


    @PutMapping
    public AjaxResult updateActivity(@RequestBody Activity activity){
        log.info("修改活动：{}",activity);
        activityService.update(activity);
        return AjaxResult.success();

    }
    @GetMapping("/listselect/{type}")
    public Result<List<Activity>> listselect(@PathVariable Integer type){
        log.info("根据渠道来源：{}",type);
        List<Activity> list= activityService.listselect(type);
        return Result.success(list);

    }

    /*
    * 条件分页查询
    * */

    @GetMapping("/list")
    private PageResult page(@ModelAttribute ActivityPageQueryDTO queryDTO){
        log.info("开始分页查询：{}",queryDTO);
        return activityService.page(queryDTO);
    }

}
